package com.base.myproject.client.HR.attendance;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BaseTreeStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.busi.BO.TreeNodeModelData;
import com.base.myproject.client.busi.print.ReportPrintDialog;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.BaseResource;
import com.base.myproject.client.system.Env;
import com.base.myproject.client.tools.CommandSyncContainer;
import com.base.myproject.client.tools.CommandSyncReturnObject;
import com.base.myproject.client.tools.CommandSyncsql;
import com.base.myproject.client.tools.GreetingService;
import com.base.myproject.client.tools.GreetingServiceAsync;
import com.base.myproject.client.tools.Tools;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseCheckGroup;
import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.TreePanelEvent;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.DateTimePropertyEditor;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanelSelectionModel;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel.CheckCascade;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel.CheckNodes;
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
 * 考勤统计表
 */
/**
 * @author mzba
 *
 */
public class Att_Rep_Statistics extends BaseJDBCPanel {
	String tree_depcode = null;// 讲当前树形结构中选中的部门id保存
	String tree_de_name = null;// 讲当前树形结构中选中的部门name保存

	TabPanel tabPanel = null;
	TreePanel<TreeNodeModelData> treePanel = null;
	// 创建树形结构的数据表
	BaseTreeStore<TreeNodeModelData> treeStore = null;
	
	DateField seach_by_date = new DateField();//查询日期
	TextField<String> seach_name = new TextField<String>();//姓名输入框
	Button seach_bt	= new Button("查询");//查询按钮
	DateField date_t1 = new DateField();//查询日期
	Button b1 = new Button("月结生成");
	
	DateField date_t3 = new DateField();//查询日期
	
	private String bcode = Env.getEnvbcode();
	private String results = null;
	private BaseCheckGroup check = null;
	private List<String> level = null;
	
	public Att_Rep_Statistics() {
		String sql = "select substring('id like '''+replace(permissionsbcode,';','%'' or id like '''),9," +
		"len('id like '''+replace(permissionsbcode,';','%'' or id like '''))-21) as result from" +
		" busipermissions where bcode = '"+bcode+"' and busicode = 8000";
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService2.getDataSet(sql, new AsyncCallback<DataSet>(){
		@Override
			public void onFailure(Throwable caught) {	
			}
			@Override
			public void onSuccess(DataSet result) {  
				if(result.getRowCount() != 0){
					results = result.getValue(0, "result");
					String sql2 = "select name,type from dictionary where type='zy'";
					final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
					greetingService2.getDataSet(sql2, new AsyncCallback<DataSet>(){
					@Override
						public void onFailure(Throwable caught) {	
						}
						@Override
						public void onSuccess(DataSet result) {  
							if(result.getRowCount() != 0){
								level = new ArrayList<String>();
								for(int i = 0;i < result.getRowCount();i++){
									level.add(result.getValue(i, "name"));
								}
							}
							init();
						}
					});
				}else{
					MessageBox.alert("提示", "抱歉，您没有查看权限", null);
				}
			}
		});
	}
	
	public void init() {
		initWeigetx();
	} 
	
	public void complete() {
		super.complete();
		print.addListener(Events.Select, getListener());
		getToolbarll().add(print);
	}
	
	public void initWeigetx() {
		HorizontalPanel hp=new HorizontalPanel();
		//hp.add(new Label("请选择部门:"));
		//hp.add(dep);
		seach_by_date.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM"));
		hp.add(new Label("查询年月:"));
		hp.add(seach_by_date);
		hp.add(new Label("匹配姓名:"));
		hp.add(seach_name);
		String title[] = level.toArray(new String[level.size()]);
		check = new BaseCheckGroup(title,true);
		check.setHeight(30);
		hp.add(new Label("雇佣级别:"));
		hp.add(check);
		
		seach_bt.addListener(Events.OnClick, getListener());
		hp.add(seach_bt);
		b1.addListener(Events.OnClick, getListener());
		hp.add(b1);
		
		VerticalPanel vp=new VerticalPanel();
		vp.setSpacing(5);
		vp.add(hp);
		
		vp.add(getBaseGrid());
		/*********************/
		ContentPanel center = new ContentPanel();
		center.setHeaderVisible(false);
		center.add(vp);
		
		BorderLayoutData northData = new BorderLayoutData(LayoutRegion.WEST,
				200);
		northData.setCollapsible(true);
		northData.setFloatable(true);
		northData.setHideCollapseTool(true);
		northData.setSplit(true);
		northData.setMargins(new Margins(5, 5, 0, 0));

		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setMargins(new Margins(5, 5, 0, 0));
		
		ContentPanel panel = new ContentPanel();
		panel.setHeading("选择部门");
		panel.setCollapsible(true);
		panel.add(getTreePanel());
		/***************************/
		
		add(panel, northData);
		add(center, centerData);
		this.layout();
	}
	/*************tree*********/
	TreePanel<TreeNodeModelData> getTreePanel() {
		if (treePanel == null) {
			initTreePanel();
		}
		return treePanel;
	}
	BaseTreeStore<TreeNodeModelData> getTreeStore() {
		if (treeStore == null) {
			initTreeStore();
		}
		return treeStore;
	}
	// 创建数据连接表
	BaseTreeStore<TreeNodeModelData> initTreeStore() {
		StoreInfo si = new StoreInfo();
		si
				.setSql("select icode,id,name from SystemInfo where id like "+results+" order by id asc");
		si.setTreesortcolumn("id");
		si.setKeyname(new String[] { "icode" });
		si.setTablename("SystemInfo");
		treeStore = new BaseTreeStore<TreeNodeModelData>(si, false);
		treeStore.load();
		return treeStore;

	}
	// 实例化TreePanel
	TreePanelSelectionModel<TreeNodeModelData> tpsm = new TreePanelSelectionModel<TreeNodeModelData>();

	void initTreePanel() {
		// super.onRender();
		treePanel = new TreePanel<TreeNodeModelData>(getTreeStore());
		treePanel.setWidth(200);
		treePanel.setHeight(445);
		treePanel.setDisplayProperty("name");
		treePanel.setSelectionModel(tpsm);
		treePanel.setCheckStyle(CheckCascade.PARENTS);
		treePanel.setCheckNodes(CheckNodes.BOTH);
		treePanel.getStyle().setLeafIcon(AbstractImagePrototype.create(BaseResource.INSTANCE
				.tree_file())); 
		treePanel.setCheckable(false);
		treePanel.setAutoLoad(true);

		treePanel.addListener(Events.OnClick,
				new Listener<TreePanelEvent<TreeNodeModelData>>() {
					public void handleEvent(TreePanelEvent<TreeNodeModelData> be) {
						String id = be.getItem().get("id").toString();
						//if (!id.equals("00")) {// 表示为主节点 不因有任何操作
							//set_grid(be);
						//}
						tree_depcode = id;// 讲当前树形结构中选中的部门id保存
						tree_de_name = be.getItem().get("name").toString();
					}
				});
	}
	/**********************************/
	// 创建数据表
	BaseStore<BusiObject> store = new BaseStore<BusiObject>();
	MessageBox boxCommand = null;
	public void to_seach(String level){
		final String ym = seach_by_date.getRawValue();
		String wherebyname = " ";
		if(seach_name.getRawValue() != null){
			wherebyname += " and a.bname like '%" + seach_name.getRawValue() + "%'";
		}
		String sql = "select distinct 年月,雇员编号,姓名,部门名称,部门编号,出勤,例假,法定假,年假,补休,其他假,上月结转,调整,本月加班, "+
						"补休*8+本月补休 as 本月补休,"+
						"上月结转+调整+本月加班-(补休*8+本月补休) as 总欠假,"+
						"convert(decimal(10,1),round((上月结转+调整+本月加班-(补休*8+本月补休))/8,1)) as 合天数  "+
					"from "+
						"(select CONVERT(varchar(7),a.ym,120) as 年月,b.employno as 雇员编号,a.bname as 姓名, "+
						"a.depcode as 部门编号,(select name from systeminfo where a.depcode=id) as 部门名称,"+
						"(select count(bc) from v_schedule where bcode=a.bcode and bc!='' and bc not in(select batchno from hr_Attendance_WorkBatch where depcode='00') and CONVERT(varchar(7),ymd,120)='"+ym+"'  and depcode like '"+tree_depcode+"%') as 出勤,"+
						"(select count(bc) from v_schedule where bc='DO' and bcode=a.bcode and CONVERT(varchar(7),ymd,120)='"+ym+"'  and depcode like '"+tree_depcode+"%') as 例假,"+
						"(select count(bc) from v_schedule where bc='PH' and bcode=a.bcode and CONVERT(varchar(7),ymd,120)='"+ym+"'  and depcode like '"+tree_depcode+"%') as 法定假,"+
						"(select count(bc) from v_schedule where bc='AL' and bcode=a.bcode and CONVERT(varchar(7),ymd,120)='"+ym+"'  and depcode like '"+tree_depcode+"%') as 年假,"+
						"(select count(bc) from v_schedule where bc='CL' and bcode=a.bcode and CONVERT(varchar(7),ymd,120)='"+ym+"'  and depcode like '"+tree_depcode+"%') as 补休, "+
						"(select count(bc) from v_schedule where bcode=a.bcode  and bc in (select batchno from hr_Attendance_WorkBatch where depcode='00' and batchno not in('CL','DO','PH','AL')) and CONVERT(varchar(7),ymd,120)='"+ym+"'  and depcode like '"+tree_depcode+"%') as 其他假,"+
						"(select isnull(convert(decimal(10, 1),sum(period)),0)  from hr_Attendance_ot where type='上月结转' and status='同意' and bcode=a.bcode and CONVERT(varchar(7),usedate,120)='"+ym+"'  and depcode like '"+tree_depcode+"%') as 上月结转, "+
						"(select isnull(sum(period),0) from v_ot where type='调整' and bcode=a.bcode and CONVERT(varchar(7),usedate,120)='"+ym+"'  and depcode like '"+tree_depcode+"%') as 调整, "+
						"(select isnull(sum(period),0)  from v_ot where type='加班' and bcode=a.bcode and CONVERT(varchar(7),usedate,120)='"+ym+"'  and depcode like '"+tree_depcode+"%') as 本月加班, "+
						"(select isnull(sum(period),0)  from v_ot where type='补休' and bcode=a.bcode and CONVERT(varchar(7),usedate,120)='"+ym+"'  and depcode like '"+tree_depcode+"%') as 本月补休 "+
						"from hr_Attendance_schedule a left join bcode_job b on a.bcode=b.bcode where CONVERT(varchar(7),ym,120)='"+ym+"'  and depcode like '"+tree_depcode+"%' "+wherebyname;
		if (!level.equals("")) sql += " and employlevel in("+level+")";
		sql += ") as att_total";
		boxCommand = MessageBox.wait("请稍侯",  
	            "", "正在查询数据...");  
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT.create(com.base.myproject.client.tools.GreetingService.class);
	    greetingService.getDataSet(sql, new AsyncCallback<DataSet>(){
			@Override
			public void onFailure(Throwable caught) {
				
			}
			@Override
			public void onSuccess(DataSet result) {
				store.removeAll();
				for(int i = 0;i < result.getRowCount();i++){
					BusiObject bo = new BusiObject();
					bo.set("ym", ym);
					bo.set("bcode", result.getValue(i, "雇员编号"));
					bo.set("bname", result.getValue(i, "姓名"));
					bo.set("depName", result.getValue(i, "部门名称"));
					bo.set("attendance1", result.getValue(i, "出勤"));
					bo.set("attendance2", result.getValue(i, "例假"));
					bo.set("attendance3", result.getValue(i, "法定假"));
					bo.set("attendance4", result.getValue(i, "年假"));
					bo.set("attendance5", result.getValue(i, "补休"));
					bo.set("attendance6", result.getValue(i, "其他假"));
					bo.set("jz", result.getValue(i, "上月结转"));
					bo.set("tz", result.getValue(i, "调整"));
					bo.set("jb", result.getValue(i, "本月加班"));
					bo.set("bx", result.getValue(i, "本月补休"));
					bo.set("zq", result.getValue(i, "总欠假"));
					bo.set("ts", result.getValue(i, "合天数"));
					
					store.add(bo,false,false);
				}
				grid.setStore(store);
				grid.getView().refresh(true);
				boxCommand.close();
			}
		});
	}
	// 创建一个grid
	BaseGrid<BusiObject> grid = null;
	BaseGrid<BusiObject> getBaseGrid() {
		if (grid == null) {
			createGrid();
		}
		return grid;
	}
	void createGrid() {
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig C1 = new ColumnConfig("ym", "年月", 65);
		//C1.setDateTimeFormat(DateTimeFormat.getFormat("yy-MM"));
		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("bname", "姓名", 50);
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("bcode", "员工编号", 80);
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("depName", "部门名称", 80);
		columns.add(C4);
		ColumnConfig C5 = new ColumnConfig("attendance1", "出勤", 45);
		columns.add(C5);
		ColumnConfig C6 = new ColumnConfig("attendance2", "例休", 45);
		columns.add(C6);
		ColumnConfig C7 = new ColumnConfig("attendance3", "法定假", 65);
		columns.add(C7);
		ColumnConfig C8 = new ColumnConfig("attendance4", "年假", 45);
		columns.add(C8);
		ColumnConfig C9= new ColumnConfig("attendance5", "补休", 45);
		columns.add(C9);
		ColumnConfig C10 = new ColumnConfig("attendance6", "其他假", 45);
		columns.add(C10);
		ColumnConfig C11 = new ColumnConfig("jz", "上月结转", 65);
		columns.add(C11);
		ColumnConfig C12 = new ColumnConfig("tz", "调整", 45);
		columns.add(C12);
		ColumnConfig C13 = new ColumnConfig("jb", "本月加班", 65);
		columns.add(C13);
		ColumnConfig C14 = new ColumnConfig("bx", "本月补休", 65);
		columns.add(C14);
		ColumnConfig C15 = new ColumnConfig("zq", " 总欠假", 65);
		columns.add(C15);
		ColumnConfig C16 = new ColumnConfig("ts", " 合天数", 65);
		columns.add(C16);
		
		ColumnModel cm = new ColumnModel(columns);
		grid = new BaseGrid<BusiObject>(store, cm ,false,false);
		cbs.setSelectionMode(SelectionMode.SINGLE);//控制是否可以多选每行后面的复选框
		grid.setSelectionModel(cbs);
		Tools.setResize(grid,0.99,0.94);
	}	
/*
 * 月结生成	
 */
	String datet1_ym;
	MessageBox boxCommand2 = null;
	public void made_to_month(String d){
		boxCommand2 = MessageBox.wait("请稍侯","", "正在生成数据..."); 
		datet1_ym = d;                      //date_t1.getRawValue();
		final String ym = seach_by_date.getRawValue();
		String wherebyname = " ";
		if(tree_depcode == null){
			MessageBox.alert("提示", "部门不能为空", null);
			return;
		}else if(ym == null){
			MessageBox.alert("提示", "年月不能为空", null);
			return;
		}
		if(seach_name.getRawValue() != null){
			wherebyname += " and a.bname like '%" + seach_name.getRawValue() + "%'";
		}
		String sql = "select distinct 年月,雇员编号,姓名,部门名称,部门编号,出勤,例假,法定假,年假,补休,其他假,上月结转,调整,本月加班, "+
						"补休*8+本月补休 as 本月补休,"+
						"上月结转+调整+本月加班-(补休*8+本月补休) as 总欠假,"+
						"convert(decimal(10,1),round((上月结转+调整+本月加班-(补休*8+本月补休))/8,1)) as 合天数  "+
					"from "+
						"(select CONVERT(varchar(7),a.ym,120) as 年月,b.employno as 雇员编号,a.bname as 姓名,"+
						" a.depcode as 部门编号,(select name from systeminfo where a.depcode=id) as 部门名称,"+
						"(select count(bc) from v_schedule where bcode=a.bcode and bc!='' and bc not in(select batchno from hr_Attendance_WorkBatch where depcode='00') and CONVERT(varchar(7),ymd,120)='"+ym+"') as 出勤,"+
						"(select count(bc) from v_schedule where bc='DO' and bcode=a.bcode and CONVERT(varchar(7),ymd,120)='"+ym+"') as 例假,"+
						"(select count(bc) from v_schedule where bc='PH' and bcode=a.bcode and CONVERT(varchar(7),ymd,120)='"+ym+"') as 法定假,"+
						"(select count(bc) from v_schedule where bc='AL' and bcode=a.bcode and CONVERT(varchar(7),ymd,120)='"+ym+"') as 年假,"+
						"(select count(bc) from v_schedule where bc='CL' and bcode=a.bcode and CONVERT(varchar(7),ymd,120)='"+ym+"') as 补休, "+
						"(select count(bc) from v_schedule where bcode=a.bcode  and bc in (select batchno from hr_Attendance_WorkBatch where depcode='00' and batchno not in('CL','DO','PH','AL')) and CONVERT(varchar(7),ymd,120)='"+ym+"') as 其他假,"+
						"isnull((select top 1 period  from hr_Attendance_ot where type='上月结转' and status='同意' and bcode=a.bcode and CONVERT(varchar(7),usedate,120)='"+ym+"'),0) as 上月结转, "+
						"(select isnull(sum(period),0) from v_ot where type='调整' and bcode=a.bcode and CONVERT(varchar(7),usedate,120)='"+ym+"') as 调整, "+
						"(select isnull(sum(period),0)  from v_ot where type='加班' and bcode=a.bcode and CONVERT(varchar(7),usedate,120)='"+ym+"') as 本月加班, "+
						"(select isnull(sum(period),0)  from v_ot where type='补休' and bcode=a.bcode and CONVERT(varchar(7),usedate,120)='"+ym+"') as 本月补休 "+
						"from hr_Attendance_schedule a inner join bcode_job b on a.bcode=b.bcode where CONVERT(varchar(7),ym,120)='"+ym+"'  and depcode like '"+tree_depcode+"%' ) "+
					"as att_total";
		System.out.println("---------------->>>>>>>>>>>>" + sql);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT.create(com.base.myproject.client.tools.GreetingService.class);
	    greetingService.getDataSet(sql, new AsyncCallback<DataSet>(){
			@Override
			public void onFailure(Throwable caught) {	
				
			}
			@Override
			public void onSuccess(DataSet result) {
				store.removeAll();
				if(result.getRowCount() > 0){
					java.util.Date currentTime = new java.util.Date();
				    String day;
					if(currentTime.getDate() < 10){
				    	day = "0" + String.valueOf(currentTime.getDate());
				    }else{
				    	day = String.valueOf(currentTime.getDate());
				    }
					/*算出当前日期*/
					String this_date = String.valueOf(currentTime.getYear()+1900) + "-" + String.valueOf(currentTime.getMonth()+1) + "-" +day;
					int year = Integer.parseInt(datet1_ym.substring(0, 4));
					int month = Integer.parseInt(datet1_ym.substring(5, 7));
					String yr,mt;
					if(month == 12){
						mt = "01";
						year = year + 1;
						yr = String.valueOf(year);
					}else{
						month = month+1;
						if(month < 10){
							mt = "0" + String.valueOf(month);
						}else{
							mt = String.valueOf(month);
						}
						yr = String.valueOf(year);
					}
					String nextMonth = yr + "-" + mt + "-01";/*算出下个月的日期*/
					String [] inset_sql_array = new String[result.getRowCount()];
					for(int i = 0;i < result.getRowCount();i++){
						String type = "上月结转";
						String bname = result.getValue(i, "姓名");
						String bcode = result.getValue(i, "雇员编号");
						bcode = bcode.substring(4, bcode.length());
						String depName = result.getValue(i, "部门名称");
						String depCode = result.getValue(i, "部门编号");
						String lastMonthData = result.getValue(i, "总欠假");
						String inset_sql = "insert into hr_Attendance_ot (signDate,useDate,bcode,name,depCode,department,type,period,status,readonly)" +
								" values('"+this_date+"','"+nextMonth+"','"+bcode+"','"+bname+"','"+depCode+"','"+depName+"','"+type+"','"+lastMonthData+"','同意',1)";
						inset_sql_array[i] = inset_sql;
					}
					save_sql(inset_sql_array,nextMonth,tree_depcode);
				}else{
					MessageBox.alert("提示", "该部门未发现已排班的员工，请检查排班或选择其他部门！", null);
					boxCommand2.close();
				}
			}
		});	
	}
	private boolean  save_sql(String [] sql_array, String m,String depCode){
		CommandSyncsql csql = new CommandSyncsql();
		String del_sql="delete from hr_Attendance_ot where CONVERT(varchar(10),useDate,120)='"+m+"' and type='上月结转' and depCode like '"+depCode+"%'";
		csql.getV().add(del_sql);
		for(int i=0;i<sql_array.length;i++){
			csql.getV().add(sql_array[i]);
		}

		if(csql.getV().size()<=0){
			return false;
		}else{
			CommandSyncContainer list = new CommandSyncContainer();
			list.add(csql);
		
			GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
			greetingService.SendCommandSync(list,new AsyncCallback<CommandSyncReturnObject>() {
				@Override
				public void onFailure(Throwable caught) {
					MessageBox.alert("错误","网络连接失败", null);
				}
				@Override
				public void onSuccess(CommandSyncReturnObject result) {
					if (result.isB()) {
						Info.display("提示信息", "操作成功");	
						boxCommand2.close();
					}
					else{
						MessageBox.alert("错误","错误，错误代码"+result.getMessage(), null);
					}
				}
			});
		}
		return true;
	}	
	
	
	int sync = 0;
	Listener<BaseEvent> defaultlistener;

	Listener<BaseEvent> getListener() {
		if (defaultlistener != null) {
			return defaultlistener;
		}
		defaultlistener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				sync++;
				try {
					if (sync == 1) {
						String level = "";
						if(check.getValueArray().length != 0){
							for(int i = 0;i < check.getValueArray().length;i++){
								String value = (String)check.getValueArray()[i];
								level += "'" + value + "'" + ",";
							}
							level = level.substring(0, level.length() - 1);
						}
						
						if (be.getType() == Events.Select) {
							if(be.getSource().equals(print)){
								if(tree_de_name==null){
									MessageBox.alert("警告", "请选择查询部门",null);
								}else if(seach_by_date.getRawValue().equals("")){
									MessageBox.alert("警告", "请选择查询月份",null);
								}else{
									String ym = seach_by_date.getRawValue();
									String name = seach_name.getRawValue() == null ? "" : seach_name.getRawValue();
									String data = tree_depcode + "_" + ym + "_" + name + "&level=" + level;;
									Window.open(GWT.getHostPageBaseURL() + "hr_Jsp/rptRepStatistics.jsp?data=" + URL.encode(data),"_blank","menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
								}
							}
						}  else if (be.getType() == Events.OnClick) {
							if (be.getSource().equals(seach_bt)) {
								if(tree_de_name==null){
									MessageBox.alert("警告", "请选择查询部门",null);
								}else if(seach_by_date.getRawValue().equals("")){
									MessageBox.alert("警告", "请选择查询月份",null);
								}else{
									to_seach(level);
								}
							}
							if (be.getSource().equals(b1)) {
								if(seach_by_date.getRawValue().equals("")){
									MessageBox.alert("警告", "请选择前面的一个时间再进行月结操作!",null);
									return ;
								}else{
									MessageBox.confirm("提示	", "您确定要对  ["+tree_de_name+" "+seach_by_date.getRawValue()+"] 的数据结转到下月吗？", new Listener<MessageBoxEvent> (){
										public void handleEvent(MessageBoxEvent be) {
											if(be.getButtonClicked().getText().equals(GXT.MESSAGES.messageBox_yes())){//选择同意后
												made_to_month(seach_by_date.getRawValue());
											}//否的时候
										}		
									});	
								}
								
							}
							
						} else if (be.getType() == Events.Change) {
							
						} else if (be.getType() == Events.KeyUp) {
							if (be instanceof ComponentEvent) {
								if (((ComponentEvent) be).getKeyCode() == 13) // 回车
								{
								}
							}
						}
					}
				} finally {
					sync--;
				}
			}

		};
		return defaultlistener;
	}
}
